package com.a0soft.gphone.aTruffleHog.gio.util;

import com.a0soft.gphone.aTruffleHog.R;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class ActivityHelperTablet extends ActivityHelper {
	   private Menu mOptionsMenu;

	    protected ActivityHelperTablet(Activity activity) {
	        super(activity);
	    }

	    @Override
	    public void onPostCreate(Bundle savedInstanceState) {
	        // Do nothing in onPostCreate. ActivityHelper creates the old action bar, we don't
	        // need to for Honeycomb.
	    }

	    @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        mOptionsMenu = menu;
	        return super.onCreateOptionsMenu(menu);
	    }

	    @Override
	    public boolean onOptionsItemSelected(MenuItem item) {
	        switch (item.getItemId()) {
	            case android.R.id.home:
	                // Handle the HOME / UP affordance. Since the app is only two levels deep
	                // hierarchically, UP always just goes home.
	                goHome();
	                return true;
	        }
	        return super.onOptionsItemSelected(item);
	    }

	    /** {@inheritDoc} */
	    @Override
	    public void setupHomeActivity() {
	        super.setupHomeActivity();
	        // NOTE: there needs to be a content view set before this is called, so this method
	        // should be called in onPostCreate.
	        if (UIUtils.isTablet(mActivity)) {
	            mActivity.getActionBar().setDisplayOptions(
	                    0,
	                    ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
	        } else {
	            mActivity.getActionBar().setDisplayOptions(
	                    ActionBar.DISPLAY_USE_LOGO,
	                    ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
	        }
	    }

	    /** {@inheritDoc} */
	    @Override
	    public void setupSubActivity() {
	        super.setupSubActivity();
	        // NOTE: there needs to be a content view set before this is called, so this method
	        // should be called in onPostCreate.
	        if (UIUtils.isTablet(mActivity)) {
	            mActivity.getActionBar().setDisplayOptions(
	                    ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO,
	                    ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
	        } else {
	            mActivity.getActionBar().setDisplayOptions(
	                    0,
	                    ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
	        }
	    }

	    /**
	     * No-op on Honeycomb. The action bar title always remains the same.
	     */
	    @Override
	    public void setActionBarTitle(CharSequence title) {
	        mActivity.getActionBar().setTitle(title);
	    }

	    /**
	     * No-op on Honeycomb. The action bar color always remains the same.
	     */
	    @Override
	    public void setActionBarColor(int color) {
	        if (!UIUtils.isTablet(mActivity)) {
	            super.setActionBarColor(color);
	        }
	    }

	    /** {@inheritDoc} */
	    @Override
	    public void setRefreshActionButtonCompatState(boolean refreshing) {
	        // On Honeycomb, we can set the state of the refresh button by giving it a custom
	        // action view.
	        if (mOptionsMenu == null) {
	            return;
	        }

	        final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
	        if (refreshItem != null) {
	            if (refreshing) {
	                refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
	            } else {
	                refreshItem.setActionView(null);
	            }
	        }
	    }
}
